package com.ruoyi.project.WebMoudle.accountDetails.controller;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.WebMoudle.ShopSuser.domain.ShopSuser;
import com.ruoyi.project.WebMoudle.ShopSuser.service.IShopSuserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.accountDetails.domain.AccountDetails;
import com.ruoyi.project.WebMoudle.accountDetails.service.IAccountDetailsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 记账详情Controller
 * 
 * @author ruoyi
 * @date 2020-07-14
 */
@Controller
@RequestMapping("/accountDetails/accountDetails")
public class AccountDetailsController extends BaseController
{
    private String prefix = "accountDetails/accountDetails";

    @Autowired
    private IAccountDetailsService accountDetailsService;
    @Autowired
    private IShopSuserService shopSuserService;

    @RequiresPermissions("accountDetails:accountDetails:view")
    @GetMapping()
    public String accountDetails()
    {
        return prefix + "/accountDetails";
    }

    /**
     * 查询记账详情列表
     */
    @RequiresPermissions("accountDetails:accountDetails:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountDetails accountDetails)
    {
        startPage();
        /*Long userId = getSysUser().getUserId();
        ShopSuser shopSuser = shopSuserService.selectOneShopId(userId);
        if (StringUtils.isNotNull(shopSuser)){
            accountDetails.setShopId(shopSuser.getShopId());
        }*/
        List<AccountDetails> list = accountDetailsService.selectAccountDetailsList(accountDetails);
        return getDataTable(list);
    }

    /**
     * 导出记账详情列表
     */
    @RequiresPermissions("accountDetails:accountDetails:export")
    @Log(title = "记账详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AccountDetails accountDetails)
    {
        List<AccountDetails> list = accountDetailsService.selectAccountDetailsList(accountDetails);
        ExcelUtil<AccountDetails> util = new ExcelUtil<AccountDetails>(AccountDetails.class);
        return util.exportExcel(list, "accountDetails");
    }

    /**
     * 新增记账详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存记账详情
     */
    @RequiresPermissions("accountDetails:accountDetails:add")
    @Log(title = "记账详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccountDetails accountDetails)
    {
        return toAjax(accountDetailsService.insertAccountDetails(accountDetails));
    }

    /**
     * 修改记账详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AccountDetails accountDetails = accountDetailsService.selectAccountDetailsById(id);
        mmap.put("accountDetails", accountDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存记账详情
     */
    @RequiresPermissions("accountDetails:accountDetails:edit")
    @Log(title = "记账详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccountDetails accountDetails)
    {
        return toAjax(accountDetailsService.updateAccountDetails(accountDetails));
    }

    /**
     * 删除记账详情
     */
    @RequiresPermissions("accountDetails:accountDetails:remove")
    @Log(title = "记账详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accountDetailsService.deleteAccountDetailsByIds(ids));
    }
}
